package captcha

import (
	"gin/common/lib/redis"
	"gin/model/body"
	"gin/model/http_error"
)

// VerifySlider 验证滑块
func VerifySlider(p body.CaptchaParam) bool {
	if p.CaptchaSliderId == "" {
		panic(http_error.CaptchaSliderError)
	}

	sliderX := p.CaptchaSliderX

	x, err := redis.GetInt(redis.GetRedisKey("CAPTCHA", p.CaptchaSliderId))
	if err != nil {
		panic(http_error.CaptchaSliderInvalidError)
	}
	max := x + 10
	min := x - 10

	if sliderX > max || sliderX < min {
		panic(http_error.CaptchaSliderError)
	}

	return true
}
